package com.sc.model;

import com.fasterxml.jackson.annotation.JsonView;

public class JResult {
	
	private static final long serialVersionUID = 1L;
	public final static JResult SUCCESS = new JResult(true, 200, null);
	public final static JResult WARN = new JResult(false, 400, null);

	public static interface JResultView {
	};

	private boolean success;
	private int code; // 200：成功 ,400：失败 ,500：系统错误
	private Object result;

	public JResult() {
	}

	public JResult(boolean success, int code, Object result) {
		this.success = success;
		this.result = result;
		this.code = code;
	}

	@JsonView(JResultView.class)
	public int getCode() {
		return code;
	}

	public void setCode(int code) {
		this.code = code;
	}

	@JsonView(JResultView.class)
	public boolean isSuccess() {
		return success;
	}

	public void setSuccess(boolean success) {
		this.success = success;
	}

	@JsonView(JResultView.class)
	public Object getResult() {
		return result;
	}

	public void setResult(Object result) {
		this.result = result;
	}

	public static JResult success(Object result) {
		return new JResult(true, 200, result);
	}

	public static JResult warn(Object result) {
		return new JResult(false, 400, result);
	}

	public static JResult warn(int code, Object result) {
		return new JResult(false, code, result);
	}

}
